<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>页眉</title>
    <!--bootstrap-->
    <script src="js/jquery.min.js"></script>
    <link href="bootstrap/css/bootstrap.min.css" rel="stylesheet">
    <script src="js/HttpUtil.js"></script>
    <script src="js/HZHHttpUtil.js"></script>
    <script src="js/CacheUtil.js"></script>
</head>
<body>
<nav class="navbar navbar-default ">
    <div class="container-fluid">
        <!-- Brand and toggle get grouped for better mobile display -->
        <div class="navbar-header">
            <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" aria-expanded="false">
                <span class="sr-only">Toggle navigation</span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
            </button>
            <a class="navbar-brand" href="#">欢迎来到天天商城</a>
        </div>

        <!-- Collect the nav links, forms, and other content for toggling -->
        <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
            <ul class="nav navbar-nav">
                <li ><a href="/shop-app/homePage.html">首页 </a></li>
                <li class="" id="login_li"><a href="/shop-app/Login.html">登录 </a></li>
                <li ><a href="/shop-app/userRegister.html">免费注册 </a></li>
                <li ><a href="#">联系我们 </a></li>
                <li ><a href="#">帮助 </a></li>
            </ul>
            <div class="navbar-form navbar-left">
                <div class="form-group">
                    <input type="text" class="form-control" placeholder="搜索" id="productSearch">
                </div>
                <button type="submit" class="btn btn-default" onclick="getSearchMessage()">点击搜索</button>
                <button class="btn btn-default" ><a href="/shop-app/accurateSearch.html">精确搜索</a></button>
            </div>
            <ul class="nav navbar-nav navbar-right">
                <li><a href="/shop-app/cartList.html">购物车</a></li>
                <li><a href="/shop-app/myOrders.html">我的订单</a></li>
                <li><a href="/shop-center/userCenter.html">会员中心</a></li>
                <li class="dropdown">
                    <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true"
                       aria-expanded="false" id="loginMessage">你好，请登录 <span class="caret"></span></a>
                    <ul class="dropdown-menu">
                        <li><a href="/shop-app/addressPage.html">我的地址</a></li>
                        <li><a href="#">个人中心</a></li>
                        <li onclick="userExit()"><a href="#">退出</a></li>

                    </ul>
                </li>
            </ul>
        </div><!-- /.navbar-collapse -->
    </div><!-- /.container-fluid -->
</nav>

<script>
    //判断用户是否登录
    $(function() {
        // 取出登录的用户
        let loginUser = getLoginUser();
        console.log("loginUser:"+loginUser)
        let userId = loginUser.userId;
        console.log("userId:"+userId)
        if(userId===null||userId===""){
            $("#loginMessage").text("你好，请登录");
            console.log("用户为空")
            $("#login_li").attr("class","")
        }else {
            $("#loginMessage").text(loginUser.userName);
            console.log("改变名字");
            console.log(loginUser.userName);
            $("#login_li").attr("class","hidden")
        }
    })

    function getSearchMessage() {
        let value = $("#productSearch").val();
        value=encodeURI(encodeURI(value));
        console.log(value);
        location.href="/shop-app/productSearch.html?keyWords="+value;
    }

    function userExit() {
        sessionStorage.removeItem("login_user");
        window.location.reload();
    }

</script>
</body>
</html>